﻿using Lights.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Lights.Processing;
using System.Collections;
using Cudafy.Host;
using Cudafy;
using System.Diagnostics;

namespace Lights.Page
{
    /// <summary>
    /// Logica di interazione per EditingPage.xaml
    /// </summary>
    public partial class EditingPage : UserControl
    {
        public Photo SelectedItem
        {
            get { return this._selected; }
            set 
            {
                this.IsEnabled = (value != null);
                this._selected = value;
                UpdatePreview(value);
            }
        }

        private PhotoProcessor processor;
        private Photo _selected;

        void UpdatePreview(Photo photo)
        {
            this.img.Source = photo.Preview;
            this.processor.SetPhoto(photo);
            this.ctrlHistogram.SetHistogram(this.processor.GetHistogram());
        }

        public EditingPage()
        {
            InitializeComponent();
            processor = PhotoProcessor.Create();
        }

        private void sldLuminance_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            processor.SetFilter("Brightness", (float)e.NewValue);
            this.img.Source = processor.GetPreview();
            this.ctrlHistogram.SetHistogram(processor.GetHistogram());
        }
    }
}
